package com.yndsoft.jc.supplier.adapter;

import android.content.Context;
import android.view.View;

import com.yndsoft.jc.R;
import com.yndsoft.jc.supplier.model.OrderModel.DetsBean;
import com.yndsoft.jc.supplier.widget.recyclerview.RecyclerAdapter;
import com.yndsoft.jc.supplier.widget.recyclerview.RecyclerHolder;
import com.yndsoft.jc.supplier.widget.recyclerview.RecyclerListener;

import java.util.List;

public class ProjectAdapter extends RecyclerAdapter<DetsBean> implements RecyclerListener.OnClickListener<RecyclerHolder> {

    public ProjectAdapter(Context context, List<DetsBean> data) {
        super(context, data, R.layout.item_project);
    }

    @Override
    public void convert(RecyclerHolder holder, DetsBean model) {

        DetsBean.ProductBean product = model.getProduct();
        if (product != null) {
            holder.setTvText(R.id.project_title, product.getName() + product.getSubname());
        }

        DetsBean.ProductattributeBean productattribute = model.getProductattribute();
        if (productattribute != null) {
            holder.setTvText(R.id.project_content, productattribute.getProject() + " | " + productattribute.getMethod() + " | " + productattribute.getStandard());
            holder.setTvText(R.id.project_money, "¥" + productattribute.getPrice());
        }

        setLine(holder);
    }

    @Override
    public void onClick(View v, int position, RecyclerHolder holder) {

    }

    private void setLine(RecyclerHolder holder) {
        View supplierLine = holder.findViewById(R.id.supplier_line);
        if (mData != null && mData.size() > 0) {
            if (holder.position == mData.size() - 1) {
                supplierLine.setVisibility(View.GONE);
            } else {
                supplierLine.setVisibility(View.VISIBLE);
            }
        }
    }
}
